using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Text;

using GeoFramework.Controls;

namespace GeoFramework.Examples
{
    public partial class ControlPerformanceTuningForm : Form
    {
        public ControlPerformanceTuningForm()
        {
            InitializeComponent();

            // Start receiving real-time GPS data
            GpsDevice.Start();
        }

        private void GlassEffectCheckBox_CheckedChanged(object sender, System.EventArgs e)
        {
            if (GlassEffectCheckBox.Checked)
            {
                // Enable the glass effect
                Altimeter.Effect = PolarControlEffect.Glass;
                Compass.Effect = PolarControlEffect.Glass;
                SatelliteViewer.Effect = PolarControlEffect.Glass;
                Speedometer.Effect = PolarControlEffect.Glass;
            }
            else
            {
                // Use no effect
                Altimeter.Effect = PolarControlEffect.None;
                Compass.Effect = PolarControlEffect.None;
                SatelliteViewer.Effect = PolarControlEffect.None;
                Speedometer.Effect = PolarControlEffect.None;
            }
        }

        private void SmoothingCheckBox_CheckedChanged(object sender, System.EventArgs e)
        {
            if (SmoothingCheckBox.Checked)
            {
                // Enable the glass effect
                Altimeter.SmoothingMode = SmoothingMode.HighQuality;
                Compass.SmoothingMode = SmoothingMode.HighQuality;
                SatelliteViewer.SmoothingMode = SmoothingMode.HighQuality;
                Speedometer.SmoothingMode = SmoothingMode.HighQuality;
            }
            else
            {
                // Use no effect
                Altimeter.SmoothingMode = SmoothingMode.HighSpeed;
                Compass.SmoothingMode = SmoothingMode.HighSpeed;
                SatelliteViewer.SmoothingMode = SmoothingMode.HighSpeed;
                Speedometer.SmoothingMode = SmoothingMode.HighSpeed;
            }
        }

        private void TextSmoothingCheckBox_CheckedChanged(object sender, System.EventArgs e)
        {
            if (TextSmoothingCheckBox.Checked)
            {
                // Enable text smoothing
                Altimeter.TextRenderingHint = TextRenderingHint.AntiAlias;
                Compass.TextRenderingHint = TextRenderingHint.AntiAlias;
                SatelliteViewer.TextRenderingHint = TextRenderingHint.AntiAlias;
                Speedometer.TextRenderingHint = TextRenderingHint.AntiAlias;
            }
            else
            {
                // Use no text smoothing effects
                Altimeter.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
                Compass.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
                SatelliteViewer.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
                Speedometer.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
            }
        }

        private void SeparateThreadCheckBox_CheckedChanged(object sender, System.EventArgs e)
        {
            if (SeparateThreadCheckBox.Checked)
            {
                // Launch rendering on their own thread
                Altimeter.IsPaintingOnSeparateThread = true;
                Compass.IsPaintingOnSeparateThread = true;
                SatelliteViewer.IsPaintingOnSeparateThread = true;
                Speedometer.IsPaintingOnSeparateThread = true;
            }
            else
            {
                // Shut down any rendering threads
                Altimeter.IsPaintingOnSeparateThread = false;
                Compass.IsPaintingOnSeparateThread = false;
                SatelliteViewer.IsPaintingOnSeparateThread = false;
                Speedometer.IsPaintingOnSeparateThread = false;
            }
        }

        private void ValueInterpolationCheckBox_CheckedChanged(object sender, System.EventArgs e)
        {
            if (ValueInterpolationCheckBox.Checked)
            {
                // Use smooth interpolation when values change
                Altimeter.ValueInterpolationMethod = InterpolationMethod.CubicEaseInOut;
                Compass.ValueInterpolationMethod = InterpolationMethod.CubicEaseInOut;
                Speedometer.ValueInterpolationMethod = InterpolationMethod.CubicEaseInOut;

                Altimeter.RotationInterpolationMethod = InterpolationMethod.CubicEaseInOut;
                Compass.RotationInterpolationMethod = InterpolationMethod.CubicEaseInOut;
                SatelliteViewer.RotationInterpolationMethod = InterpolationMethod.CubicEaseInOut;
                Speedometer.RotationInterpolationMethod = InterpolationMethod.CubicEaseInOut;
            }
            else
            {
                // Use no interpolation
                Altimeter.ValueInterpolationMethod = InterpolationMethod.Snap;
                Compass.ValueInterpolationMethod = InterpolationMethod.Snap;
                Speedometer.ValueInterpolationMethod = InterpolationMethod.Snap;

                Altimeter.RotationInterpolationMethod = InterpolationMethod.Snap;
                Compass.RotationInterpolationMethod = InterpolationMethod.Snap;
                SatelliteViewer.RotationInterpolationMethod = InterpolationMethod.Snap;
                Speedometer.RotationInterpolationMethod = InterpolationMethod.Snap;
            }
        }

        private void FrameRateTrackBar_Scroll(object sender, System.EventArgs e)
        {
            Altimeter.TargetFramesPerSecond = FrameRateTrackBar.Value;
            Compass.TargetFramesPerSecond = FrameRateTrackBar.Value;
            SatelliteViewer.TargetFramesPerSecond = FrameRateTrackBar.Value;
            Speedometer.TargetFramesPerSecond = FrameRateTrackBar.Value;
        }
    }
}